// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-08 15:18
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.TREE;

import com.DataStruct.Tree.TwoBinaryTree.TreeNode;

public class IsUnivalTree {
    /**
     * 单值二叉树判断
     */
    int val;

    public boolean isUnivalTree(TreeNode root) {
        if (root == null) {
            return false;
        }
        val = root.val;
        return Search(root);
    }

    private boolean Search(TreeNode root) {
        if (root == null) {
            return false;
        }
        if (root.val != val) {
            return false;
        }
        boolean left = true, right = true;
        if (root.left != null) {
            left = Search(root.left);
        }
        if (root.right != null) {
            right = Search(root.right);
        }
        return left && right;
    }
}
